package com.ease.common.reflect;

import java.io.File;

import org.apache.commons.lang.StringUtils;

import xjavadoc.XClass;

/**
 * 
 * @author nathanleewei
 * 
 */
@Deprecated
/* refer to ActionScriptMappingProject */
public class SourceVisitor {

	private File sourceFile;

	private XClass xclazz;

	public static File getSourceFile(String sourceDir, Class<?> clazz) {

		String className = clazz.getCanonicalName();
		String fileSeparator = System.getProperty("file.separator");
		if (fileSeparator == null || "".equals(fileSeparator)) {
			fileSeparator = File.separator;
		}
		className = StringUtils.replace(className, ".", fileSeparator);
		int index = className.indexOf('$');
		if (index > 0) {
			className = className.substring(index);
		}
		className = className + ".java";
		String temp = sourceDir.trim();
		StringBuilder sb = new StringBuilder(temp);
		if (temp.endsWith("/")) {
			sb.append(className);
		} else {
			sb.append(File.separatorChar).append(className);
		}
		File file = new File(sb.toString());
		if (file.exists()) {
			return file;
		}
		return null;
	}

	public void init(SourceVisitorCallback sourceVisitorCallback) {
		// sourceFile = getSourceFile(sourceDir, clazz);
		// SourceSet sourceSet = new FileSourceSet(sourceFile);
		// XJavaDoc javaDoc = new XJavaDoc();
		// javaDoc.addSourceSet(sourceSet);
		// xclazz = javaDoc.getXClass(clazz.getSimpleName());
		// Class<?>[] interfaces = clazz.getInterfaces();
		// Class<?> superclass = clazz.getSuperclass();
	}

	/**
	 * @return the sourceFile
	 */
	public File getSourceFile() {
		return sourceFile;
	}

	/**
	 * @param sourceFile
	 *            the sourceFile to set
	 */
	public void setSourceFile(File sourceFile) {
		this.sourceFile = sourceFile;
	}

	/**
	 * @return the xclazz
	 */
	public XClass getXclazz() {
		return xclazz;
	}

	/**
	 * @param xclazz
	 *            the xclazz to set
	 */
	public void setXclazz(XClass xclazz) {
		this.xclazz = xclazz;
	}

}
